package com.liaoyifan.core.generator;

import com.liaoyifan.core.valid.Lang;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class EntityModel {

    @SuppressWarnings("unchecked")
    public static void build(Map<String, Object> dataModel) {
        List<Column> columns = (List<Column>) dataModel.get("columns");
        if (columns.stream().anyMatch(i -> Lang.eq(i.getJavaName(), "id"))) {
            dataModel.putIfAbsent("hasIdColumn", true);
        }
        if (columns.stream().anyMatch(i -> Lang.isNotBlank(i.getColumnComment()))) {
            dataModel.putIfAbsent("importSchema", true);
        }
        if (columns.stream()
                .anyMatch(i -> Lang.eq(BigDecimal.class.getName(), i.getImportClass()))) {
            dataModel.putIfAbsent("importBigDecimal", true);
        }
        if (columns.stream()
                .anyMatch(i -> Lang.eq(LocalDate.class.getName(), i.getImportClass()))) {
            dataModel.putIfAbsent("importLocalDate", true);
        }
        if (columns.stream()
                .anyMatch(i -> Lang.eq(LocalDateTime.class.getName(), i.getImportClass()))) {
            dataModel.putIfAbsent("importLocalDateTime", true);
        }
    }
}
